package com.wbl.train.common.context;

import com.wbl.train.common.member.entity.PassengerEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Author: 王博纶
 * Date: 2024/1/26 16:56
 * FileName: LoginMemberContext
 * Description: 会员登录的上下文信息类
 */
public class LoginMemberContext {
    private static final Logger log = LoggerFactory.getLogger(LoginMemberContext.class);

    // 创建本地线程对象
    private static final ThreadLocal<PassengerEntity> member = new ThreadLocal<>();

    public static PassengerEntity getMember(){
        return member.get();
    }

    public static void setMember(PassengerEntity member){
        LoginMemberContext.member.set(member);
    }

    public static Long getId(){
        try {
            return member.get().getId();
        } catch (Exception e) {
            log.error("获取登录会员信息异常",e);
            throw e;
        }
    }
}
